package com.github.admin.edu.oauth.server.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-7-13
 */
@Configuration
public class WebViewConfiguration implements WebMvcConfigurer {

    @Value("${file.config.image-path}")
    private String imagePath;
    @Value("${file.config.file-path}")
    private String filePath;
    @Value("${file.config.other}")
    private String other;


    public void addInterceptors(InterceptorRegistry registry){


    }

    /**
     * 常用静态文件路径配置
     * @param registry
     */
    public void  addResourceHandlers(ResourceHandlerRegistry registry){

        //css,js,常用插件，路径映射
        registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/");
        //registry.addResourceHandler("/files/**").addResourceLocations("file:///var/spring/uploaded_files");
        //TODO： 特别注意  在win环境下 路径最后一定要加“/”
        registry.addResourceHandler("/static/upload/**").addResourceLocations(filePath);
        //图片保存路径映射，此路径需要登录后才能查看
        registry.addResourceHandler("/uc/image/**").addResourceLocations("file:///"+imagePath);
        //图片保存路径映射，此路径无需登录，即可查看
        registry.addResourceHandler("/s/uc/image/**").addResourceLocations("file:///"+imagePath);
        //文件保存路径映射，此路径需要登录才能查看
        registry.addResourceHandler("/uc/file/**","/s/uc/file/**").addResourceLocations("file:///"+filePath);
        //其它文件映射路径
        registry.addResourceHandler("/uc/other/**","/s/uc/other").addResourceLocations("file:///"+other);
    }

}
